<!DOCTYPE html>
<html>

  <head>
    <meta charset="UTF-8">
    <title>gameserver edit</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/static/super_cmdb/css/font.css">
    <link rel="stylesheet" href="/static/super_cmdb/css/xadmin.css">

  </head>

  <body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="server_name" class="layui-form-label">
                  <span class="x-red">*</span>游戏名称
              </label>
              <div class="layui-input-inline" style="width: 400px;">
                  <input type="text" id="server_name" name="server_name" required="" lay-verify="nikename" value="{{ gameserver_info.server_name }}"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="server_dir" class="layui-form-label">
                  <span class="x-red">*</span>游戏目录
              </label>
              <div class="layui-input-inline" style="width: 400px;">
                  <input id="server_dir" name="server_dir" required="" lay-verify="host_ip" value="{{ gameserver_info.server_dir }}"
                  autocomplete="off" class="layui-input">
              </div>
          </div>

          <div class="layui-form-item">
              <label for="server_ip" class="layui-form-label">
                  <span class="x-red">*</span>ip地址
              </label>
              <div class="layui-input-inline" style="width: 400px;">
                  <input id="server_ip" name="server_ip" required="" lay-verify="server_ip" value="{{ gameserver_info.server_ip }}"
                  autocomplete="off" class="layui-input">
              </div>
          </div>

            <div class="layui-form-item">
              <label for="b_group_id" class="layui-form-label">
                  <span class="x-red">*</span>游戏分区
              </label>
              <div class="layui-input-inline">
                  <select id="b_group_id" name="b_group_id">
                        <option value="{{ current_id_group_info.id }}">{{ current_id_group_info.group_name }}</option>
                        {% for b_group in b_group_list %}
                            <option value="{{ b_group.id }}">{{ b_group.group_name }}</option>
                        {% endfor %}
                  </select>
              </div>
            </div>
          <div class="layui-form-item" >
              <label for="L_repass" class="layui-form-label">
              </label>
              <button id="my_edit" class="layui-btn" lay-filter="edit" lay-submit="">
                  确认修改
              </button>
          </div>
      </form>
    </div>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.cookie.js"></script>
    <script>

        $(function () {
            $.ajaxSetup({
                beforeSend:function (xhr,settings) {
                    xhr.setRequestHeader("X-CSRFtoken",$.cookie("csrftoken"));
                }
            })
        });

      layui.use(['form','layer'], function(){
          $ = layui.jquery;
        var form = layui.form
        ,layer = layui.layer;

        //自定义验证规则
        form.verify({
          nikename: function(value){
            if(value.length < 1){
              return '昵称至少得1个字符啊';
            }
          }
          ,pass: [/(.+){6,12}$/, '密码必须6到12位']
          ,repass: function(value){
              if($('#L_pass').val()!=$('#L_repass').val()){
                  return '两次密码不一致';
              }
          }
        });


        //监听提交
        form.on('submit(edit)', function(data){
          console.log(data);
          //发异步，把数据提交给php
            $.ajax({
                    url: "/super_cmdb/gameserver_edit-{{ gameserver_info.id }}/",
                    type: "POST",
                    //data: $('#layui-form').serialize(),
                    data: {
                        "server_name":$("#server_name").val(),
                        "server_dir":$("#server_dir").val(),
                        "server_ip":$("#server_ip").val(),
                        "b_group_id":$("#b_group_id").val(),
                        "clean_status":$("#clean_status").val(),
                        "cross_status":$("#cross_status").val(),
                    },
                    success: function (data) {
                        if (data.code == 0){
                            layer.alert(data.msg, {icon: 6});
                        } else {
                            layer.alert(data.msg, {icon: 7});
                        }
                    }
                });
          return false;
        });


      });

  </script>
  </body>

</html>
